﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Imaging;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI;
using Windows.UI.Popups;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Shapes;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace SignatureApp
{
  /// <summary>
  /// An empty page that can be used on its own or navigated to within a Frame.
  /// </summary>
  public sealed partial class MainPage : Page
  {
    public MainPage()
    {
      this.InitializeComponent();
    }

    private async void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
    {
      var destfile = await KnownFolders.PicturesLibrary.CreateFileAsync("Signatures\\test.png",
        CreationCollisionOption.ReplaceExisting
      );

      var signatureStream = await Signature.GetSignaturePngStreamAsync();
      await FileIO.WriteBytesAsync(destfile, signatureStream.ToArray());

      await new MessageDialog("Signature saved!").ShowAsync();

    }

    private void Button_Clear(object sender, Windows.UI.Xaml.RoutedEventArgs e)
    {
      this.Signature.Clear();
    }

  }
}
